package com.newly.common.core.utils;

import cn.hutool.core.util.ObjectUtil;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: newly-parent
 * @remark: 数据转换
 * @author: guan
 * @create: 2022-01-13 17:17
 */
public class ConverseUtils {

    public static List<Long> toLong(List<?> list) {
        if (ObjectUtil.isEmpty(list)) return null;
        return list.stream().map(l -> Long.parseLong(l.toString())).collect(Collectors.toList());
    }

    public static List<String> toString(List<?> list) {
        if (ObjectUtil.isEmpty(list)) return null;
        return list.stream().map(l -> l.toString()).collect(Collectors.toList());
    }

    public static List<String> toString(Object[] objs) {
        if (ObjectUtil.isEmpty(objs)) return null;
        return Arrays.stream(objs).map(l -> l.toString()).collect(Collectors.toList());
    }

    public static List<Integer> toInteger(List<?> menuIds) {
        if (ObjectUtil.isEmpty(menuIds)) return null;
        return menuIds.stream().map(menuId -> Integer.parseInt(menuId.toString()))
                .collect(Collectors.toList());
    }
}
